package tp.pr5.items;

import tp.pr5.Constants;
import tp.pr5.NavigationModule;
import tp.pr5.RobotEngine;

/**
 * The garbage is a type of item that generates recycled material after using it. The garbage can be used only once. After using it, it must be removed from the robot inventory
 * @author VICTOR & HENAR
 */
public class Garbage extends Item {

	private int recycledMaterial;
	private boolean used = false;
	
	/**
	 * Garbage constructor
	 * @param id - Item id
	 * @param description - Item description
	 * @param recycledMaterial - The amount of recycled material that the item generates
	 */
	public Garbage(String id, String description, int recycledMaterial) {
		super(id, description);
		this.recycledMaterial = recycledMaterial;
	}

	/**
	 * Garbage can be used only once
	 * @return true if the item has not been used yet
	 * @see Item.canBeUsed()
	 */
	@Override
	public boolean canBeUsed() {
		return (!this.used);
	}

	/**
	 * The garbage generates recycled material for the robot that uses it
	 * @param r - the robot that uses the item
	 * @param p - The place where the item is used
	 * @return true if the garbage was transformed in recycled material
	 * @see Item.use(tp.pr2.RobotEngine, tp.pr2.Place)
	 */
	@Override
	public boolean use(RobotEngine r, NavigationModule nav) {
		if (this.canBeUsed())
		{
			this.used = true;
			r.addRecycledMaterial(this.recycledMaterial);
			return true;
		}
		else
		{ 
			r.saySomething("WALL·E says: What a pity! I have no more " + this.getId() + " in my inventory" + Constants.LINE_SEPARATOR);
			return false;
		}
	}

	/**
	 * Generates a String with the Item description
	 * @see Object.toString()
	 */
	public String toString()
	{
		return super.toString() + "// used = " + this.used;
	}

}
